 <script type="text/javascript">
 
adder={
        get: function()
        {
          alert("dsddscv  dfd");
        }
};



function addAssociation(mainType) {
    var typeForm = document.forms[mainType];
    var addDivId = 'associationsAddDiv';
    var fillingDiv = 'associationsDiv';
    var assoType = 'depends';
    var reason = "";
    if ($('updateFix')) {
        $('updateFix').parentNode.removeChild($('updateFix'));
    }
    var tempSpan = document.createElement('span');
    tempSpan.id = "updateFix";

    if (mainType != "depForm") {
        reason += validateForInput(typeForm.type, org_wso2_carbon_registry_relations_ui_jsi18n["type"]);
        if (reason == "") {
            reason += validateEmpty(typeForm.type, org_wso2_carbon_registry_relations_ui_jsi18n["type"]);
        }
        if (reason == "") {
            reason += validateNotExists(typeForm.associationPaths.value);
        }

        if (reason == "") {
            typeForm.type.value = typeForm.type.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
            if (typeForm.type.value == "") {
                reason = org_wso2_carbon_registry_relations_ui_jsi18n["association.type.cannot.contain.only.white.spaces"];
            }
        }
        assoType = typeForm.type.value;
        if (assoType == "depends") {
            fillingDiv = 'dependenciesDiv';
        }
    } else {

        fillingDiv = 'dependenciesDiv';
        addDivId = "dependenciesAddDiv";
    }

    if (reason == "") {
        reason += validateForInput(typeForm.associationPaths, org_wso2_carbon_registry_relations_ui_jsi18n["path"]);
    }
    if (reason == "") {
        reason += validateEmpty(typeForm.associationPaths, org_wso2_carbon_registry_relations_ui_jsi18n["path"]);
    }
    if (reason == "") {
        reason += validateNotExists(typeForm.associationPaths.value);
    }
    if (reason == "") {
        reason += validateAssocationNotExists($('resourcePath').value,
                            typeForm.associationPaths.value, assoType);
    }

    if (reason == "") {
        typeForm.associationPaths.value = typeForm.associationPaths.value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
        if (typeForm.associationPaths.value == "") {
            reason = org_wso2_carbon_registry_relations_ui_jsi18n["path.cannot.contain.only.white.spaces"];
        }
    }

    if (reason == "") {
        var resourcePath = $('resourcePath').value;
        var associationPaths = typeForm.associationPaths.value;
        typeForm.type.value = "";
        typeForm.associationPaths.value = "";
        showHideCommon(addDivId);
        new Ajax.Request('../relations/association-list-ajaxprocessor.jsp',
        {
            method:'post',
            parameters:{path:resourcePath,type:assoType,associationPaths:associationPaths,todo:'add'},
            onSuccess: function(transport) {
                $(fillingDiv).innerHTML = transport.responseText;
                $(fillingDiv).appendChild(tempSpan);
                $(fillingDiv).style.display = "";
                if (fillingDiv == "associationsDiv") {
                    $('associationsIconExpanded').style.display = "";
                    $('associationsIconMinimized').style.display = "none";

                    YAHOO.util.Event.onAvailable('updateFix', function() {
                        $('associationsSum').style.display = "none";
                        $('associationsList').style.display = "";

                    });


                } else {
                    $('dependenciesIconExpanded').style.display = "";
                    $('dependenciesIconMinimized').style.display = "none";
                    YAHOO.util.Event.onAvailable('updateFix', function() {
                        $('dependenciesSum').style.display = "none";
                        $('dependenciesList').style.display = "";
                    });

                }

            },
            onFailure: function(transport) {
                CARBON.showErrorDialog(transport.responseText);
            }
        });

    }
    else {
        CARBON.showWarningDialog(reason);
    }
}

function addDependency() {
    addAssociation('depForm');
}

function validateNotExists(pickedPath) {
    if (pickedPath.charAt(0) != '/') {
        // this is a not a registry path, so avoid validating
        return "";
    }
    var error = "";
    new Ajax.Request('../resources/resource_exists_ajaxprocessor.jsp',
    {
        method:'post',
        parameters: {pickedPath: pickedPath},
        asynchronous:false,
        onSuccess: function(transport) {
            var returnValue = transport.responseText;
            if (returnValue.search(/----ResourceExists----/) == -1) {
                error = org_wso2_carbon_registry_relations_ui_jsi18n["resource.does.not.exist"]+ " <strong>" + pickedPath + "</strong>.";
            }
        },
        onFailure: function() {

        }
    });
    return error;
}


function validateAssocationNotExists(source, destination, type) {
    var error = "";
    new Ajax.Request('../relations/asssociation_exists_ajaxprocessor.jsp',
    {
        method:'post',
        parameters: {path: source, destination: destination, type: type},
        asynchronous:false,
        onSuccess: function(transport) {
            var returnValue = transport.responseText;
            if (returnValue.search(/----AssocationExists----/) != -1) {
                error = org_wso2_carbon_registry_relations_ui_jsi18n["the.given"] +" " + (type == "depends"? org_wso2_carbon_registry_relations_ui_jsi18n["dependency"]: org_wso2_carbon_registry_relations_ui_jsi18n["association"]) + " " + org_wso2_carbon_registry_relations_ui_jsi18n["already.exists"] + " " +
                        org_wso2_carbon_registry_relations_ui_jsi18n["you.cant.have.duplicate"] + " " + (type == "depends"? org_wso2_carbon_registry_relations_ui_jsi18n["dependencies"]: org_wso2_carbon_registry_relations_ui_jsi18n["associations"]);
            }
        },
        onFailure: function() {

        }
    });
    return error;
}

function editDependencyPaths(mainType, resoPath, assocPaths)
{
    var typeForm = document.forms[mainType];
    fillingDiv = 'dependenciesDiv';
    addDivId = "dependenciesAddDiv";
    var assoType = 'depends';
    var reason = "";

    if ($('updateFix')) {
        $('updateFix').parentNode.removeChild($('updateFix'));
    }
    var tempSpan = document.createElement('span');
    tempSpan.id = "updateFix";

    /*resourcePath = resoPath;

    associationPaths = assocPaths;*/

    if (reason == "") {
        var resourcePath = $('resourcePath').value;
        var associationPaths = typeForm.associationPaths.value;
        typeForm.type.value = "";
        typeForm.associationPaths.value = "";

        new Ajax.Request('../relations/association-list-ajaxprocessor.jsp',
        {
            method:'post',
            parameters:{path:resourcePath,type:assoType,associationPaths:associationPaths,todo:'edit'},
            onSuccess: function(transport) {
                $(fillingDiv).innerHTML = transport.responseText;
                $(fillingDiv).appendChild(tempSpan);
                $(fillingDiv).style.display = "";

                if (fillingDiv == "associationsDiv") {
                    $('associationsIconExpanded').style.display = "";
                    $('associationsIconMinimized').style.display = "none";

                    YAHOO.util.Event.onAvailable('updateFix', function() {
                        $('associationsSum').style.display = "none";
                        $('associationsList').style.display = "";

                    });

                } else {

                    $('dependenciesIconExpanded').style.display = "";
                    $('dependenciesIconMinimized').style.display = "none";
                    YAHOO.util.Event.onAvailable('updateFix', function() {
                        $('dependenciesSum').style.display = "none";
                        $('dependenciesList').style.display = "";
                    });

                }
                editAssociationPaths('assoForm', resoPath, assocPaths);
            },
            onFailure: function(transport) {
                CARBON.showErrorDialog(transport.responseText);
            }
        });


    }
    else {
        CARBON.showWarningDialog(reason);
    }
}

function editAssociationPaths(mainType, resoPath, assocPaths)
{
    var typeForm = document.forms[mainType];
    fillingDiv = 'associationsDiv';
    addDivId = "associationsAddDiv";
    var assoType = typeForm.type.value;
    var reason = "";

    if ($('updateFix')) {
        $('updateFix').parentNode.removeChild($('updateFix'));
    }
    var tempSpan = document.createElement('span');
    tempSpan.id = "updateFix";

    /*resourcePath = resoPath;

    associationPaths = assocPaths;*/

    assoType = typeForm.type.value;

    if (reason == "") {
        var resourcePath = $('resourcePath').value;
        if (!resourcePath) {
            resourcePath = resoPath;
        }
        var associationPaths = typeForm.associationPaths.value;
        if (!associationPaths) {
            associationPaths = assocPaths;
        }
        typeForm.type.value = "";
        typeForm.associationPaths.value = "";

        new Ajax.Request('../relations/association-list-ajaxprocessor.jsp',
        {
            method:'post',
            parameters:{path:resourcePath,type:assoType,associationPaths:associationPaths,todo:'edit'},
            onSuccess: function(transport) {
                $(fillingDiv).innerHTML = transport.responseText;
                $(fillingDiv).appendChild(tempSpan);
                $(fillingDiv).style.display = "";

                if (fillingDiv == "associationsDiv") {
                    $('associationsIconExpanded').style.display = "";
                    $('associationsIconMinimized').style.display = "none";

                    YAHOO.util.Event.onAvailable('updateFix', function() {
                        $('associationsSum').style.display = "none";
                        $('associationsList').style.display = "";

                    });

                } else {
                    $('dependenciesIconExpanded').style.display = "";
                    $('dependenciesIconMinimized').style.display = "none";
                    YAHOO.util.Event.onAvailable('updateFix', function() {
                        $('dependenciesSum').style.display = "none";
                        $('dependenciesList').style.display = "";
                    });

                }
            },
            onFailure: function(transport) {
                CARBON.showErrorDialog(transport.responseText);
            }
        });

    }
    else {
        CARBON.showWarningDialog(reason);
    }
}

function removeAssociation(resourcePath, associationPaths, assoType, fillingDiv, status) {
    if (status != 1)
    {
        CARBON.showConfirmationDialog(org_wso2_carbon_registry_relations_ui_jsi18n["are.you.sure.you.want.to.delete"] + " <strong>'" + associationPaths + "'</strong> " + org_wso2_carbon_registry_relations_ui_jsi18n["permanently"], function() {

            if ($('updateFix')) {
                $('updateFix').parentNode.removeChild($('updateFix'));
            }
            var tempSpan = document.createElement('span');
            tempSpan.id = "updateFix";

            new Ajax.Request('../relations/association-list-ajaxprocessor.jsp',
            {
                method:'post',
                parameters:{path:resourcePath,type:assoType,associationPaths:associationPaths,todo:'remove'},
                onSuccess: function(transport) {
                    $(fillingDiv).innerHTML = transport.responseText;
                    $(fillingDiv).appendChild(tempSpan);
                    $(fillingDiv).style.display = "";
                    if (fillingDiv == "associationsDiv") {
                        $('associationsIconExpanded').style.display = "";
                        $('associationsIconMinimized').style.display = "none";

                        YAHOO.util.Event.onAvailable('updateFix', function() {
                            $('associationsSum').style.display = "none";
                            $('associationsList').style.display = "";

                        });


                    } else {
                        $('dependenciesIconExpanded').style.display = "";
                        $('dependenciesIconMinimized').style.display = "none";
                        YAHOO.util.Event.onAvailable('updateFix', function() {
                            $('dependenciesSum').style.display = "none";
                            $('dependenciesList').style.display = "";
                        });

                    }

                },
                onFailure: function(transport) {
                    CARBON.showErrorDialog(transport.responseText);
                }
            });
        }, null);
    }
    else
    {
        if ($('updateFix')) {
            $('updateFix').parentNode.removeChild($('updateFix'));
        }
        var tempSpan = document.createElement('span');
        tempSpan.id = "updateFix";
        new Ajax.Request('../relations/association-list-ajaxprocessor.jsp',
        {
            method:'post',
            parameters:{path:resourcePath,type:assoType,associationPaths:associationPaths,todo:'remove'},
            onSuccess: function(transport) {
                $(fillingDiv).innerHTML = transport.responseText;
                $(fillingDiv).appendChild(tempSpan);
                $(fillingDiv).style.display = "";
                if (fillingDiv == "associationsDiv") {
                    $('associationsIconExpanded').style.display = "";
                    $('associationsIconMinimized').style.display = "none";

                    YAHOO.util.Event.onAvailable('updateFix', function() {
                        $('associationsSum').style.display = "none";
                        $('associationsList').style.display = "";

                    });

                } else {
                    $('dependenciesIconExpanded').style.display = "";
                    $('dependenciesIconMinimized').style.display = "none";
                    YAHOO.util.Event.onAvailable('updateFix', function() {
                        $('dependenciesSum').style.display = "none";
                        $('dependenciesList').style.display = "";
                    });
                }

                if (assoType != 'depends')
                {
                    removeAssociation(resourcePath, associationPaths, 'depends', 'dependenciesDiv', 1);
                }
            },
            onFailure: function(transport) {
                CARBON.showErrorDialog(transport.responseText);
            }
        });
    }
}

function showAssociationTree(toShow, resourcePath) {
    //This variable is use to address the cashe issue in IE
    var random = Math.floor(Math.random() * 2000);
    sessionAwareFunction(function() {
        var loadingContent = null;
        if (toShow == "depends") {
            loadingContent = "<div class=\"ajax-loading-message\">" +
                             "<img src=\"images/ajax-loader.gif\" align=\"top\"/>" +
                             "<span>" + org_wso2_carbon_registry_relations_ui_jsi18n["dependency.tree.loading"] + "</span>" +
                             "</div>";
            new Ajax.Request('../relations/assoTree-ajaxprocessor.jsp', {
                method: 'get',
                parameters: {type:"depends",random:random, path:resourcePath},
                onSuccess: function(transport) {
                    CARBON.showPopupDialog(loadingContent, org_wso2_carbon_registry_relations_ui_jsi18n["dependency.tree"], 500, true);
                    var dialog = $('dialog');
                    dialog.innerHTML = transport.responseText;
                },
                onFailure: function() {
                    CARBON.showWarningDialog(org_wso2_carbon_registry_relations_ui_jsi18n["no.dependencies"]);
                }
            });
            //new Ajax.Updater("dialog", "../relations/assoTree-ajaxprocessor.jsp", {method:"get",parameters:{type:"depends",random:random, path:resourcePath} });
        } else if (toShow == "asso") {
            loadingContent = "<div class=\"ajax-loading-message\">" +
                             "<img src=\"images/ajax-loader.gif\" align=\"top\"/>" +
                             "<span>" + org_wso2_carbon_registry_relations_ui_jsi18n["association.tree.loading"] + "</span>" +
                             "</div>";
            new Ajax.Request('../relations/assoTree-ajaxprocessor.jsp', {
                method: 'get',
                parameters: {type:"asso",random:random, path:resourcePath},
                onSuccess: function(transport) {
                    CARBON.showPopupDialog(loadingContent, org_wso2_carbon_registry_relations_ui_jsi18n["association.tree"], 500, true);
                    var dialog = $('dialog');
                    dialog.innerHTML = transport.responseText;
                },
                onFailure: function() {
                    CARBON.showWarningDialog(org_wso2_carbon_registry_relations_ui_jsi18n["no.associations"]);
                }
            });
            //new Ajax.Updater("dialog", "../relations/assoTree-ajaxprocessor.jsp", {method:"get",parameters:{type:"asso",random:random, path:resourcePath}});
        }

    }, org_wso2_carbon_registry_relations_ui_jsi18n["session.timed.out"]);

}
function showAssociations() {
    if ($('associationsIconExpanded').style.display == "none") {
        //We have to expand all and hide sum
        $('associationsIconExpanded').style.display = "";
        $('associationsIconMinimized').style.display = "none";
        $('associationsExpanded').style.display = "";
        $('associationsMinimized').style.display = "none";
    }
    else {
        $('associationsIconExpanded').style.display = "none";
        $('associationsIconMinimized').style.display = "";
        $('associationsExpanded').style.display = "none";
        $('associationsMinimized').style.display = "";
    }
}
function showDependencies() {
    if ($('dependenciesIconExpanded').style.display == "none") {
        //We have to expand all and hide sum
        $('dependenciesIconExpanded').style.display = "";
        $('dependenciesIconMinimized').style.display = "none";
        $('dependenciesExpanded').style.display = "";
        $('dependenciesMinimized').style.display = "none";
    }
    else {
        $('dependenciesIconExpanded').style.display = "none";
        $('dependenciesIconMinimized').style.display = "";
        $('dependenciesExpanded').style.display = "none";
        $('dependenciesMinimized').style.display = "";
    }
}

</script>